package book;

import static org.junit.jupiter.api.Assertions.*;

import java.time.LocalDate;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class BookDaoImplTest {

	//1.创建对象
	BookDaoImpl bdi = new BookDaoImpl();
	
	@BeforeEach
	void testInsert() {
		bdi.insert(new Book(1,"a","a",false,null,1));
		bdi.insert(new Book(2,"b","a",true,LocalDate.now(),8));
		bdi.insert(new Book(3,"c","a",false,null,5));
		bdi.insert(new Book(4,"d","a",true,LocalDate.of(2022, 4, 26),6));
		bdi.insert(new Book(5,"e","a",false,null,3));
		bdi.insert(new Book(6,"f","a",true,LocalDate.of(2022, 4, 25),7));
	}

	@Test
	void testUpdate() {
		bdi.update(new Book(3,"cc","a",false,null,5));
	}

	@Test
	void testRent() {
		bdi.rent(3);
	}

	@Test
	void testBack() {
		bdi.back(2);
	}

	@Test
	void testSelectById() {
		Book b = bdi.selectById(2);
		System.out.println(b);
	}

	@AfterEach
	void testSelectAll() {
		System.out.println("------------------");
		Book[] bs = bdi.selectAll();
		for(Book b : bs) {
			System.out.println(b);
		}
		System.out.println("------------------");
	}

	@Test
	void testSortByRentTime() {
		System.out.println("------------------");
		Book[] bs = bdi.sortByRentTime();
		for(Book b : bs) {
			System.out.println(b);
		}
		System.out.println("------------------");
	}

}
